package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.ProxyIntroduceMapper;
import org.linlinjava.litemall.db.domain.ProxyIntroduce;
import org.linlinjava.litemall.db.domain.ProxyIntroduceExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhy
 * @date 2019-01-14 14:14
 **/
@Service
public class LitemallProxyService {
	@Resource
	private ProxyIntroduceMapper proxyIntroduceMapper;

	public ProxyIntroduce findById(Integer id){
		return proxyIntroduceMapper.selectByPrimaryKeyWithLogicalDelete(id,false);
	}
	public void add(ProxyIntroduce proxyIntroduce) {
		proxyIntroduceMapper.insertSelective(proxyIntroduce);
	}

	public void updateById(ProxyIntroduce proxyIntroduce) {
		proxyIntroduceMapper.updateByPrimaryKey(proxyIntroduce);
	}

	public int deletedById(Integer id) {
		return proxyIntroduceMapper.deleteByPrimaryKey(id);
	}

	public List<ProxyIntroduce> querySelective(String name, Integer page, Integer size) {
		ProxyIntroduceExample proxyIntroduceExample = new ProxyIntroduceExample();
		ProxyIntroduceExample.Criteria criteria = proxyIntroduceExample.createCriteria();
		if (!StringUtils.isEmpty(name)) {
			criteria.andNameLike("%" + name + "%");
		}
		criteria.andDeletedEqualTo(false);
		PageHelper.startPage(page, size);
		PageHelper.orderBy("id");
		return proxyIntroduceMapper.selectByExample(proxyIntroduceExample);
	}

	public int countByQuerySelective(String name, Integer page, Integer size) {
		ProxyIntroduceExample proxyIntroduceExample = new ProxyIntroduceExample();
		ProxyIntroduceExample.Criteria criteria = proxyIntroduceExample.createCriteria();
		if (!StringUtils.isEmpty(name)) {
			criteria.andNameLike("%" + name + "%");
		}
		criteria.andDeletedEqualTo(false);
		PageHelper.startPage(page, size);
		return (int)proxyIntroduceMapper.countByExample(proxyIntroduceExample);
	}

	public List<ProxyIntroduce> queryAll(){
		ProxyIntroduceExample proxyIntroduceExample = new ProxyIntroduceExample();
		ProxyIntroduceExample.Criteria criteria = proxyIntroduceExample.createCriteria();
		criteria.andDeletedEqualTo(false);
		return proxyIntroduceMapper.selectByExample(proxyIntroduceExample);
	}
}
